package com.greateamd.timetableasy.server.dao;

import java.sql.SQLException;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import org.hibernate.HibernateException;
import org.springframework.security.access.prepost.PreAuthorize;

import com.greateamd.timetableasy.client.domain.AuthType;
import com.greateamd.timetableasy.domain.Event;
import com.greateamd.timetableasy.domain.User;


public interface UserDAO extends IBaseDao<User, String>  {

	//----------------------- Rights
	@Override @PreAuthorize("hasRole('ROLE_ADMIN')")
	void delete(User user) throws HibernateException,SQLException,IllegalAccessException ;
	
	@Override @PreAuthorize("hasRole('ROLE_ADMIN')")
    public void save(User user) throws HibernateException,SQLException;
	
	@Override @PreAuthorize("hasRole('ROLE_ADMIN')")
    public void save(List<User> users) throws HibernateException,SQLException;

	@Override @PreAuthorize("hasRole('ROLE_ADMIN')")
    public void update(User user)throws HibernateException,SQLException,IllegalAccessException;
	
	
	
	//----------------------- Functionnality
	List<User> getAllCampusManager()throws HibernateException,SQLException;
	List<User> getAllTeachers()throws HibernateException,SQLException;
	@PreAuthorize("hasRole('ROLE_ADMIN')")
	List<User> getUserWithoutPromotion()throws HibernateException,SQLException;

	@PreAuthorize("hasRole('ROLE_USER')")
	List<Event> getPlanning(User user, Date from, Date to)throws HibernateException,SQLException;
	@PreAuthorize("hasRole('ROLE_TEACHER')")
	Collection<Event> getTeacherPlanning(User user, Date from, Date to)throws HibernateException,SQLException;

	@PreAuthorize("hasRole('ROLE_ADMIN')")
	void removeUserAuth(User user, AuthType auth)throws HibernateException,SQLException;
	@PreAuthorize("hasRole('ROLE_ADMIN')")
	void addUserAuth(User user, AuthType auth)throws HibernateException,SQLException;
	@PreAuthorize("hasRole('ROLE_USER')")
	boolean addEvent(Event event)throws HibernateException,SQLException, IllegalAccessException;
	
	boolean getTeacherDisponibility(Integer excluseThisEventId,String teacherUsername,Date from,int duration)throws HibernateException,SQLException;
}
